package com.zhang.crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.crm.constant.Constants;
import com.zhang.crm.mapper.TCustomerRemarkmapper;
import com.zhang.crm.pojo.TCustomerRemark;
import com.zhang.crm.service.CustomerRemarkService;
import com.zhang.crm.util.UserUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerRemarkServiceImpl implements CustomerRemarkService {

    @Resource
    private TCustomerRemarkmapper tCustomerRemarkmapper;

    @Override
    public Boolean addCustomerRemark(TCustomerRemark tCustomerRemark) {
        tCustomerRemark.setCreateBy(UserUtil.getUserInfo().getId());
        tCustomerRemark.setCreateTime(new Date());
        int insert = tCustomerRemarkmapper.insert(tCustomerRemark);
        return insert > 0 ? true: false;
    }

    @Override
    public PageInfo<TCustomerRemark> getCustomerRemarkList(Integer customerId, Integer current) {
        PageHelper.startPage(current, Constants.PAGE_DATA_SIZE);

        List<TCustomerRemark> customerRemarkList = tCustomerRemarkmapper.selectCustomerRemarkListByCustomerId(customerId);

        PageInfo<TCustomerRemark> tCustomerRemarkPageInfo = new PageInfo<>(customerRemarkList);
        return tCustomerRemarkPageInfo;
    }

    @Override
    public Boolean updateCustomerRemark(TCustomerRemark tCustomerRemark) {
        tCustomerRemark.setEditBy(UserUtil.getUserInfo().getId());
        tCustomerRemark.setEditTime(new Date());
        int i = tCustomerRemarkmapper.updateByPrimaryKeySelective(tCustomerRemark);
        return i > 0 ? true : false;
    }

    @Override
    public Boolean logicDeleteCustomerRemark(Integer customerRemarkId) {
        TCustomerRemark tCustomerRemark = new TCustomerRemark();
        tCustomerRemark.setId(customerRemarkId);
        tCustomerRemark.setEditBy(UserUtil.getUserInfo().getId());
        tCustomerRemark.setEditTime(new Date());
        tCustomerRemark.setDeleted(1);
        int i = tCustomerRemarkmapper.updateByPrimaryKeySelective(tCustomerRemark);
        return  i > 0 ? true : false;
    }
}
